import React, { Component } from 'react';
import { connect } from 'dva';
import { message, Modal, Pagination, Popconfirm, Button } from 'antd';
import styles from './../Users.css';
import moment from 'moment';
import Factory from '../../factory';
import * as datetime from '../../../utils/datetime'
import dataEditCreate from '../../addons/DataEdit'
import dataTableCreate from '../../addons/DataTable'
import * as menuService from '../../../services/menus'
import * as com from '../../../utils/common';
import BaseYgjsTzForm from './BaseYgjsTzForm'
/**国债 */
const daoName = "VBaseYgjsTzDs";
const ButtonGroup = Button.Group;
const columns = [
    { title: '序号', dataIndex: 'LSH', key: 'LSH', width: 130, sorter: true, dispaly: true, filter: true },
    { title: '生效日期', dataIndex: 'DTID', key: 'DTID', width: 110, sorter: true, dispaly: true, filter: true },
    { title: '业务类别', dataIndex: 'YWMC', key: 'YWMC', width: 110, sorter: true, dispaly: true, filter: true },
    { title: '员工号', dataIndex: 'SysUserID', key: 'SysUserID', width: 110, sorter: true, dispaly: true, filter: true },
    { title: '员工姓名', dataIndex: 'SysUserName', key: 'SysUserName', width: 120, sorter: true, dispaly: true, filter: true },
    { title: '时点基数(元)', className: 'column-money', caption: "SDJS", render: data => com.formatNumber(data.SDJS), key: 'SDJS', width: 120, sorter: true, dispaly: true, filter: true },
    { title: '日均基数(元)', className: 'column-money', caption: "RJJS", render: data => com.formatNumber(data.RJJS), key: 'RJJS', width: 120, sorter: true, dispaly: true, filter: true },
];
const controls = [
    { name: 'LSH', required: true, type: 'text', label: '序号', grid: 12 / 24 },
    { name: 'DTID', required: true, type: 'text', label: '生效日期', grid: 12 / 24 },
    { name: 'YWMC', required: true, type: 'number', label: '业务类别', grid: 12 / 24 },
    { name: 'SysUserID', required: true, type: 'alphanum', label: '员工号', grid: 12 / 24 },
    { name: 'SysUserName', required: true, type: 'date', label: '员工姓名', grid: 12 / 24 },
    { name: 'SDJS', required: true, type: 'date', label: '时点基数(元)', grid: 12 / 24 },
    { name: 'RJJS', required: true, type: 'date', label: '日均基数(元)', grid: 12 / 24 },
]
const EditFrom = dataEditCreate(daoName);
const DataTable = dataTableCreate(daoName);
class V_INDI_YGJS_TZForm extends Component {
    constructor(props) {
        super(props);
        this.state = {
            dataChange: false
        };
    }
    componentDidMount() {
        this.props.dispatch({
            type: `${daoName}/setKeyName`,
            payload: { keyName: "ID", permID: this.props.permID }
        });
        this.props.dispatch({
            type: `${daoName}/fetch`,
            payload: { daoName, page: 1, pageSize: 20 }
        });
        this.loadOptionData();
    }
    componentWillReceiveProps(nextProps) {
        const { showEdit } = this.props
        if (!nextProps.showEdit && showEdit) {
            this.props.dispatch({
                type: `${daoName}/fetch`,
                payload: { daoName, page: 1, pageSize: 20 }
            });
        }
    }
    loadOptionData() {
        let options = []
        controls.map(c => {
            if (c.fetch) {
                let f = c.fetch;
                if (c.type === 'cascader-select') {
                    f.isCascader = true;
                }
                if (c.type !== 'search') {
                    options.push(f);
                }
            }
        })
        if (daoName && options.length > 0) {
            this.props.dispatch({ type: `${daoName}/fetchOptions`, payload: { options } });
        }
    }
    showModelHandler(isAdd) {
        let key = null
        if (!isAdd) {
            const len = this.props.selectedRowKeys.length;
            if (len === 0) {
                message.info('请选择要修改的数据行！');
                return;
            }
            key = this.props.selectedRowKeys[len - 1]
        }
        this.props.dispatch({
            type: `${daoName}/openEdit`,
            payload: { key }
        });
    }
    render() {
        let { showEdit, record, permID, popedomTypes } = this.props
        const pTypes = popedomTypes[permID]
        let controlsFilter=[]
        if(pTypes.indexOf("2")!==-1){
            controlsFilter.push({ name: 'CX', required: false, type: 'button-group', grid: 5 / 24, data: [{ value: '1', label: '新增', onClick: this.showModelHandler.bind(this) }], grid: 5 / 24 })
        }
        return (
            <div className={styles.normal} style={{ background: '#fff', marginTop: -16, padding: '5px 5px' }}>
                <div>
                    <div className={styles.create}>
                        <EditFrom ref="findForm" daoName={daoName} controls={controlsFilter} clearItemMargin={true} />
                    </div>
                    <BaseYgjsTzForm ref="divi" LSH={record.LSH} title={"基数调整"} showEdit={showEdit} parentModel={daoName} />
                    <DataTable ref="userTable" daoName={daoName} columns={columns} controls={controls} permID={permID}/>
                </div>
            </div>
        )
    }
}
function mapStateToProps(state) {
    const { showEdit, record, selectedRowKeys, keyName } = state[daoName];
    const { userID, orgID, pOrgID, popedomTypes } = state.menus;
    return {
        userID,
        orgID,
        pOrgID,
        popedomTypes,
        showEdit,
        selectedRowKeys,
        keyName,
        record
    }
}
V_INDI_YGJS_TZForm = connect(mapStateToProps)(V_INDI_YGJS_TZForm)
export default V_INDI_YGJS_TZForm;
let render = (props) => React.createElement(V_INDI_YGJS_TZForm, props);

let f = new Factory()
f.set("V_INDI_YGJS_TZForm", render)


